package com.huanhuan.doc;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

public class ESTest_Client_doc_Get {
    public static void main(String[] args) throws Exception{
        final String hostname = "localhost";
        final int port = 9200;
        final String scheme = "http";
        HttpHost httphost = new HttpHost(hostname, port,scheme);
        //创建环境
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder( httphost )
        );

        //查询数据
        GetRequest request = new GetRequest();
        request.index("user").id("1001");

        GetResponse response = client.get( request, RequestOptions.DEFAULT );

        System.out.println(response.getSourceAsString());

        client.close();
    }
}
